KEY Statements (Assignment) ---------------------------------------------------------------------------- Action Assign soft-key string values to function keys, then display the values and enable or disable the function-key display line. Syntax KEY n%, stringexpression$ KEY ON KEY OFF KEY LIST Remarks The argument n% is a number representing the function key. The values for n% are 1 to 10 for the function keys, and 30 and 31 for function keys F11 and F12 on 101-key keyboards. The stringexpression$ is a string of up to 15 characters that is returned when the function key is pressed. If the stringexpression$ is longer than 15 characters, the extra characters are ignored. The KEY statements allows you to designate special "soft-key" functions -- strings that are returned when function keys are pressed. Assigning a null string to a soft key disables the function key as a soft key. If the function key number is not in the correct range, BASIC generates the error message Illegal function call, and the previous key string expression is retained. You can display soft keys with the KEY ON, KEY OFF, and KEY LIST statements. ----------------------------------------------------------------------------- Statement Action ---------------------------------------------------------------------------- KEY ON Displays the first six characters of the soft-key string values on the bottom line of the screen. KEY OFF Erases the soft-key display from the bottom line, making that line available for program use. It does not disable the function keys. KEY LIST Displays all soft-key values on the screen, with all 15 characters Statement Action ---------------------------------------------------------------------------- the screen, with all 15 characters of each key displayed. If a soft key is pressed, the effect is the same as if the user typed the string associated with the soft key. INPUT$, INPUT, and INKEY$ all can be used to read the string produced by pressing the soft key. See Also ON event; Appendix A, "Keyboard Scan Codes and ASCII Character Codes" Examples The following examples show how to assign values to soft keys. First is an example of assigning and disabling a soft key. KEY LIST displays key values after KEY 4 has been assigned and again after it has been disabled. KEY 4, "MENU" + CHR$(13) ' Assigns to soft key 4 the string KEY LIST' "MENU" followed by a carriage return. KEY 4, "" ' Disables soft key 4. KEY LIST This is an example of using KEY statements to set up one-key equivalents of menu selections. For example, pressing the F1 key is the same as entering the string "Add". CLS ' Clear screen. DIM KeyText$(3) DATA Add, Delete, Quit ' Assign soft-key strings to F1 to F3. FOR I = 1 TO 3 READ KeyText$(I) KEY I, KeyText$(I) + CHR$(13) ' String followed by Enter. NEXT I ' Print menu. PRINT " Main Menu" . PRINT PRINT " Add to list (F1)" PRINT " Delete from list (F2)" PRINT " Quit (F3)" . PRINT ' Get input and respond. DO LOCATE 7,1 . PRINT SPACE$(50); LOCATE 7,1 . INPUT " Enter your choice.", R$ SELECT CASE R$ CASE "Add", "Delete" LOCATE 10,1 . PRINT SPACE$(15); LOCATE 10,1 . PRINT R$; CASE "Quit" EXIT DO CASE ELSE LOCATE 10,1 . PRINT "Enter first word or press key." END SELECT LOOP